package net.sansi.v3correctserver.entity.screen;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import net.sansi.v3correctserver.dto.v3serverapi.V3ServerApiScreenDto;
import net.sansi.v3correctserver.entity.IntPoint;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Fang
 * create time : 2024/11/4
 * IDE : IntelliJ IDEA
 */

@EqualsAndHashCode(callSuper = true)
@ApiModel("扫描板（机箱）")
@Data
public class ScanBoard extends Rect {

    @ApiModelProperty("id")
    private String id;

    @ApiModelProperty("名称")
    private String name;

    @ApiModelProperty("类型")
    private Integer type;

    @ApiModelProperty("类型名称")
    private String typeName;

    @ApiModelProperty("型号")
    private String model;

    @ApiModelProperty("addr")
    private String addr;

    private List<Panel> panels;

    /**
     * 从 V3 响应中转换为本地 扫描板
     *
     * @param sb v3扫描板
     * @return 本地 Scanboard
     */
    public static ScanBoard of(V3ServerApiScreenDto.AllStatusResp.V3ScanBoard sb) {
        ScanBoard scanBoard = new ScanBoard();
        scanBoard.setId(sb.getLayout().getId());
        scanBoard.setStart(new IntPoint(
                sb.getLayout().getScreenX(),
                sb.getLayout().getScreenY()
        ));
        List<Panel> panels = new ArrayList<>();
        for (V3ServerApiScreenDto.AllStatusResp.V3Panel panel : sb.getStatus().getPanels()) {
            panels.add(Panel.of(panel, scanBoard));
        }
        scanBoard.setPanels(panels);
        return scanBoard;
    }
}
